package com.pan.handle.resp.config;

import java.io.IOException;
import java.io.InputStream;

public interface DefaultHtmlRead {


    public default InputStream read500Html(){
        InputStream inputStream = DefaultHtmlRead.class
                .getClassLoader().getResourceAsStream("html/500.html");
        return inputStream;
    }

    public default InputStream read404Html(){
        InputStream inputStream = DefaultHtmlRead.class
                .getClassLoader().getResourceAsStream("html/404.html");
        return inputStream;
    }
    public default String getString(InputStream inputStream){
        int len = 0;
        byte[] buf = new byte[1024];
        String result = "";
        while (true){
            try {
                if ((len = inputStream.read(buf))==-1){
                    break;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            result += new String(buf,0,len);
        }
        return result;
    }
    public default String get404HtmlString(){
        InputStream inputStream = this.read404Html();
        return getString(inputStream);
    }

    public default String get500HtmlString(){
        InputStream inputStream = this.read500Html();
        return getString(inputStream);
    }
}
